﻿@{
    ViewBag.Title = "OrderDetailList";
    Layout = "~/Areas/Shared/_spList.cshtml";
}
@model Kaiser.Modules.DC.Models.OrderDetailInput
<div region="center" border="false" style="width: 500px; height: 300px; margin: 1px;
    padding: 0px; overflow-y: hidden">
    <div id="grid">
    </div>
</div>
<div id="Dlg-Edit" title="编辑" style="width: 500px; height: 250px;">
    <div style="padding: 20px 20px 40px 40px;">
        <form method="post" id="Form1">
        <table>
            <tr>
                <td class="itemtxt">
                    您的姓名：
                </td>
                <td>
                    @Html.HiddenFor(m => Model.OrderDetailCode)
                    @Html.TextBoxFor(m => Model.OrderDetailFullName, new { @Class = "easyui-validatebox", @required = "true", @style = "width: 200px;", @maxlength = "10" })
                </td>
            </tr>
            <tr>
                <td style="text-align: right">
                    预定的奶茶：
                </td>
                <td>
                    @* @Html.(m => Model.OrderProductCode, new { @Class = "easyui-validatebox", @required = "true",@validType="string", @style = "width: 200px;" })*@
                    @Html.TextBoxFor(m => Model.OrderProductCode, new { @Class = "easyui-combogrid", @required = "true", @style = "width: 200px;", @maxlength = "10" })
                </td>
            </tr>
            <tr>
                <td style="text-align: right">
                    奶茶的冷热：
                </td>
                <td>
                    <label>@Html.RadioButton("OrderProductIsHot", false,true)冷</label>
                    <label>@Html.RadioButton("OrderProductIsHot", true,false)热</label>
                </td>
            </tr>
            <tr>
                <td style="text-align: right">
                    所属餐次：
                </td>
                <td>
                    @Html.TextBoxFor(m => Model.OrderCode, new { @Class = "easyui-combogrid", @required = "true", @style = "width: 200px;", @maxlength = "10" })
                </td>
            </tr>
        </table>
        </form>
    </div>
</div>
<script type="text/javascript">
    // 全局变量
    var grid;
    var dlg_Edit;
    var dlg_Edit_form;
    var searchWin;
    var searchForm;
    var virpath = ""; //网站的虚拟目录 如：/ShopManager
    var config = {
        ListActionURL: '@Url.Action("OrderDetailList", "DCManage", new { area = "DC" })',
        AddActionURL: '@Url.Action("AddOrderDetail", "DCManage", new { area = "DC" })',
        DelActionURL: '@Url.Action("DelOrderDetail", "DCManage", new { area = "DC" })',
        EditActionURL: '@Url.Action("EditOrderDetail", "DCManage", new { area = "DC" })'
    };


    $(function () {
        $('#OrderProductCode').combogrid({
            panelWidth: 500,
            url: '@Url.Action("GetProductList", "DCManage", new { area = "DC" })',
            idField: 'ProductCode',
            textField: 'ProductName',
            mode: 'remote',
            fitColumns: true,
            columns: [[
                    { field: 'ProductName', title: '奶茶名称', width: 60 },
                    { field: 'ProductPrice', title: '价格', width: 80 }
                ]]
        });

        $('#OrderCode').combogrid({
            panelWidth: 500,
            url: '@Url.Action("GetOrderList", "DCManage", new { area = "DC" })',
            idField: 'OrderCode',
            textField: 'OrderName',
            mode: 'remote',
            fitColumns: true,
            columns: [[
                    { field: 'OrderName', title: '描述', width: 60 },
                    { field: 'OrderCreateUserFullName', title: '发布人', width: 80 }
                ]]
        });

        grid = $('#grid').datagrid({
            title: '我要点餐',
            iconCls: 'icon-save',
            methord: 'post',
            url: config.ListActionURL,
            method: 'post',
            sortName: 'OrderTime',
            sortOrder: 'OrderTime',
            idField: 'OrderDetailCode',
            pageSize: 10,
            striped: true,
            frozenColumns: [[
	                { field: 'ck', checkbox: true }
				]],
            columns: [[
					{ field: 'ProductName', title: '预定奶茶', width: 150, sortable: true },
                    { field: 'IsHot', title: '冷/热', width: 150, sortable: true },
                    { field: 'OrderName', title: '所属餐次', width: 150, sortable: true },
                    { field: 'OrderDetailFullName', title: '预定人姓名', width: 150, sortable: true },
                    { field: 'OrderTime', title: '预定时间', width: 150, sortable: true }
				]],
            fit: true,
            pagination: true,
            rownumbers: true,
            fitColumns: true,
            singleSelect: false,
            toolbar: [{
                text: '我要点餐',
                iconCls: 'icon-add',
                handler: add
            }, '-', {
                text: '修改',
                iconCls: 'icon-edit',
                handler: edit
            }, '-', {
                text: '删除',
                iconCls: 'icon-remove',
                handler: del
            }], onDblClickRow: function (rowIndex, rowData) {  //双击事件
                dlg_Edit.dialog('open');
                dlg_Edit_form.form('clear');
                dlg_Edit.dialog('setTitle', '您正在修改:' + rowData.OrderName);
                dlg_Edit_form.form('load', rowData); //加载到表单的控件上      

                dlg_Edit_form.url = virpath + config.EditActionURL + '?id=' + rowData.OrderDetailCode;

            }, onHeaderContextMenu: function (e, field) {
                e.preventDefault();
                if (!$('#tmenu').length) {
                    createColumnMenu();
                }
                $('#tmenu').menu('show', {
                    left: e.pageX,
                    top: e.pageY
                });
            }



        });

        dlg_Edit = $('#Dlg-Edit').dialog({
            closed: true,
            modal: true,
            toolbar: [{
                text: '保存',
                iconCls: 'icon-save',
                handler: saveData
            }, '-', {
                text: '关闭',
                iconCls: 'icon-no',
                handler: function () {
                    dlg_Edit.dialog('close');
                }
            }]

        });
        dlg_Edit_form = dlg_Edit.find('form');


        $('#btn-search,#btn-search-cancel').linkbutton();
        searchWin = $('#search-window').window({
            iconCls: 'icon-search',
            closed: true,
            modal: true
        });
        searchForm = searchWin.find('form');

        $('body').layout();

    });




    function createColumnMenu() {
        var tmenu = $('<div id="tmenu" style="width:100px;"></div>').appendTo('body');
        var fields = grid.datagrid('getColumnFields');
        for (var i = 0; i < fields.length; i++) {
            $('<div iconCls="icon-ok"/>').html(fields[i]).appendTo(tmenu);
        }
        tmenu.menu({
            onClick: function (item) {
                if (item.iconCls == 'icon-ok') {
                    grid.datagrid('hideColumn', item.text);
                    tmenu.menu('setIcon', {
                        target: item.target,
                        iconCls: 'icon-empty'
                    });
                } else {
                    grid.datagrid('showColumn', item.text);
                    tmenu.menu('setIcon', {
                        target: item.target,
                        iconCls: 'icon-ok'
                    });
                }
            }
        });
    }

    function getSelectedArr() {
        var ids = [];

        var rows = $('#grid').datagrid('getSelections');
        for (var i = 0; i < rows.length; i++) {
            ids.push(rows[i].OrderDetailCode);
        }

        return ids;
    }
    function getSelectedID() {
        var ids = getSelectedArr();
        return ids.join(',');
    }
    function arr2str(arr) {
        return arr.join(',');
    }

    function add() {
        dlg_Edit_form.form('clear');
        dlg_Edit.dialog('open');
        dlg_Edit.dialog('setTitle', '我要点餐');

        $("#OrderDetailCode").val(NewGuid());



        dlg_Edit_form.url = virpath + config.AddActionURL;

        //Msgalert("提示", '成功调用', "info");    
    }
    function edit() {
        var rows = grid.datagrid('getSelections');
        var num = rows.length;
        if (num == 0) {
            Msgshow('请选择一条记录进行操作!');
            //$.messager.alert('提示', '请选择一条记录进行操作!', 'question');       
            return;
        }
        else if (num > 1) {
            Msgfade('您选择了多条记录,只能选择一条记录进行修改!'); //$.messager.alert('提示', '您选择了多条记录,只能选择一条记录进行修改!', 'info');
            return;
        }
        else {
            dlg_Edit_form.form('clear');
            dlg_Edit.dialog('open');

            dlg_Edit.dialog('setTitle', '您正在修改' + rows[0].OrderName + '分类');
            dlg_Edit_form.form('load', rows[0]); //加载到表单的控件上       

            dlg_Edit_form.url = virpath + config.EditActionURL + '?id=' + rows[0].OrderDetailCode;

        }
    }
    function del() {
        var arr = getSelectedArr();

        //alert(arr);
        if (arr.length > 0) {
            $.messager.confirm('提示信息', '您确认要删除选中的所有记录吗?', function (data) {
                if (data) {
                    $.ajax({
                        url: virpath + config.DelActionURL + '?ids=' + arr2str(arr),
                        type: 'post',
                        error: function () {
                            Msgalert('错误', '删除失败!', 'error');
                            grid.datagrid('clearSelections');
                        },
                        success: function (Result) {
                            var data = eval('(' + Result + ')');
                            if (data.success) {
                                Msgfade(arr.length + "条记录" + data.msg); //提示消息
                                grid.datagrid('reload');
                                grid.datagrid('clearSelections');
                            } else {
                                Msgalert('错误', data.msg, 'error');
                            }
                        }
                    });
                }
            });
        } else {
            Msgshow('请先选择要删除的记录。');

        }
    }
    function saveData() {
       
        //alert(dlg_Edit_form.url);
        dlg_Edit_form.form('submit', {
            url: dlg_Edit_form.url,
            onSubmit: function () {
                return $(this).form('validate');
            },
            success: function (result) {
                successCallback(result);

            }
        });
    }
    function showAll() {
        grid.datagrid({ url: virpath + config.ListActionURL });
    }

    function OpensearchWin() {
        searchWin.window('open');
        searchForm.form('clear');
    }
    function SearchOK() {
        var ProductName = $("#S_ProductName").val();
        searchWin.window('close');
        grid.datagrid({ url: virpath + config.ListActionURL, queryParams: { ProductName: ProductName} });
    }

    function closeSearchWindow() {
        searchWin.window('close');
    }
</script>
